<!doctype html>
<html>
<head>
	<meta charset='utf-8'>
</head>
<body>
<?php
	require('./init.php');
	//用户总数
	$count=$redis->lsize('uid');
	
	//页大小
	$page_size=3;
	//当前页码
	$page_num=!empty($_GET['page'])?$_GET['page']:1;
	//页总数
	$page_count=ceil($count/$page_size);
	
	$ids=$redis->lrange('uid',($page_num-1)*$page_size,$page_size*$page_num-1);
	
	$data=array();
	foreach($ids as $v){
		$data[]=$redis->hgetall('user:'.$v);
		
	}
	//
?>
<a href='./reg.html'>注册</a>
<?php
	if(!empty($_COOKIE['auth'])){
	$uid=$redis->get('auth:'.$_COOKIE['auth']);
	$username=$redis->hget('user:'.$uid,'username');
?>
	欢迎您,<?php echo $username?>
	<a href="./logout.php">退出</a>
<?php
 }else{
?>
	<a href="./login.php">登陆</a>
	
<?php	 
 } 
 ?>


<table border='1'>
	<tr>
		<td>user_id</td>
		<td>username</td>
		<td>password</td>
		<td>age</td>
		<td>操作</td>
	</tr>
	<?php foreach($data as $k=>$v){ ?>
		<tr>
			<td><?php echo $v['user_id']?></td>
			<td><?php echo $v['username'] ?></td>
			<td><?php echo $v['password'] ?></td>
			<td><?php echo $v['age'] ?></td>
			<td>
				<a href="./del.php?user_id=<?php echo $v['user_id']?>">删除</a>
				<a href="./modi.php?user_id=<?php echo $v['user_id']?>">修改</a>
				<?php
					if(!empty($_COOKIE['auth']) && $uid != $v['user_id']){
					
				?>
				<a href="./addfans.php?myid=<?php echo $uid?>&user_id=<?php echo $v['user_id']?>">加关注</a>
				<?php }?>
			</td>
		</tr>
	<?php } ?>	
	<tr>
		<td colspan=5>
			<a href="./list.php?page=1">首页</a>
			<a href="./list.php?page=<?php echo ($page_num-1)<1?1:$page_num-1 ?>">上一页</a>
			<a href="./list.php?page=<?php echo ($page_num+1)>$page_count?$page_count:$page_num+1 ?>">下一页</a>
			<a href="./list.php?page=<?php echo $page_count ?>">尾页</a>
			<a href=""></a>
			<a href=""></a>
			<a href=""></a>
		</td>
	</tr>
</table>
<table border='1'>
	<caption>我关注的人</caption>
	<tr>
		<td>user_id</td>
		<td>username</td>
		<td>age</td>
		
	</tr>
	<?php
		$array_uid=$redis->smembers('user:'.$uid.':following');
		$data=array();
		foreach($array_uid as $v){
			$data[]=$redis->hgetall('user:'.$v);
			
		}
	?>
	<?php foreach($data as $k=>$v){ ?>
		<tr>
			<td><?php echo $v['user_id']?></td>
			<td><?php echo $v['username'] ?></td>
			<td><?php echo $v['age'] ?></td>
		</tr>
	<?php } ?>	
	
</table>
<table border='1'>
	<caption>我的粉丝</caption>
	<tr>
		<td>user_id</td>
		<td>username</td>
		<td>age</td>
		
	</tr>
	<?php
		$array_uid=$redis->smembers('user:'.$uid.':followers');
		$data=array();
		foreach($array_uid as $v){
			$data[]=$redis->hgetall('user:'.$v);
			
		}
	?>
	<?php foreach($data as $k=>$v){ ?>
		<tr>
			<td><?php echo $v['user_id']?></td>
			<td><?php echo $v['username'] ?></td>
			<td><?php echo $v['age'] ?></td>
		</tr>
	<?php } ?>	
	
</table>
</body>
</html>